/****************************************************************************

	COPYRIGHT(C) MAXSI SOFTWARE, JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010

    This file is part of Maxsi Engine.

    Maxsi Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Maxsi Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	*/ #include "MaxsiEngineContributors.h" /*

	If you modify this file, please enter your name below and provide contact
	information in MaxsiEngineContributors.h. For more information please see
	MaxsiEngineContributors.h.
	
	Contributors to this file:

	- Jonas 'Sortie' Termansen
	- [your name here]

	MaxsiEngine.dll
	A linkable version of Maxsi Engine.

	MaxsiIOFileSystem.h
	A Simple Flexible Async I/O FileSystem.

****************************************************************************/
#if !defined(ME_IODisabled) || defined(ME_IOEnabled)
#ifndef MaxsiIOFileSystem_H
#define MaxsiIOFileSystem_H

namespace MaxsiEngine
{
	class	ME_IOFileSystem;
	
	CLASSLINK ME_IOFileSystem : public ME_IOConnection
	{
	public:
		ME_DECLARE_COMPONENT("ME_IOFileSystem", ME_IOFileSystem, ME_IOConnection);

	public:
		ME_IOFileSystem();
		~ME_IOFileSystem();
	
	public:
		char*						IFileName;
		char*						OFileName;
		HANDLE						IFileHND;
		HANDLE						OFileHND;
		bool						IFileWriting;
		bool						OFileReading;
		ME_OVERLAPPED				IOverlapped; // The writing overlapped.
		ME_OVERLAPPED				OOverlapped; // The reading overlapped.

	public:
		bool						OpenWrite(char* File);
		bool						OpenRead(char* File);

	public:
		virtual	SIZE_T				IBufferRequired(); // Minimum amount of buffer space 'required' to function.
		virtual	SIZE_T				OBufferRequired(); // Minimum amount of buffer space 'required' to function.
		virtual	SIZE_T				IBufferSuggested(); // Recommended amount of buffer space.
		virtual	SIZE_T				OBufferSuggested(); // Recommended amount of buffer space.
		virtual	int					IPolicy(); // The flag ME_IO_CTX_* for the this connection.
		virtual	int					OPolicy(); // The flag ME_IO_CTX_* for the this connection.
		virtual int					ORangePolicy(); // Specifies if this connection has defined behavior for only requesting ranges of data
		virtual int					IRangePolicy(); // Specifies if this connection has defined behavior for only requesting ranges of data
		// ?:
		virtual	bool				IIConnect(ME_IOConnectionPointer* Remote);
		virtual	bool				OOConnect(ME_IOConnectionPointer* Remote);
		virtual	bool				Connected(ME_IOConnectionPointer* Connection);
		virtual	bool				IIConnected();
		virtual	bool				IOConnected();
		virtual	bool				OIConnected();
		virtual	bool				OOConnected();
		virtual	bool				IIDisconnect();
		virtual	bool				OODisconnect();
		virtual	bool				IIDisconnected();
		virtual	bool				IODisconnected();
		virtual	bool				OIDisconnected();
		virtual	bool				OODisconnected();
		virtual	bool				Disconnect(ME_IOConnectionPointer* Connection); // When Connection should be disconnected
		virtual	bool				Disconnect(); // Disconnects II, IO, OI, and OO.
		virtual	bool				Disconnected(ME_IOConnectionPointer* Connection); // When Connection has been disconnected
		virtual	bool				Disconnected(); // When II, IO, OI, and OO has disconnected.
	
	public:
		virtual	SIZE_T				GetIBytesAvailable(); // Returns the amount of bytes that can be sent through the input-channel at the moment
		virtual	SIZE_T				GetOBytesAvailable(); // Returns the amount of bytes than can be sent through the output-channel at the moment

	public:
		virtual	bool				OnThink(); // Please call Think(), not OnThink(), for debugging and threading reasons.
		virtual	bool				OnOThink();
		virtual	bool				OnIThink();

	public:
		virtual	bool				EvaluateConnection(); // Return true if the connection still has something to do - return false if it has nothing to do and could be shut down with no harm.

	public:
		virtual	void				DoneIO(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped);

	};

}


#endif
#endif
